package club.babyf.nativeai.entity;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;

/**
 * ToolCallAccumulator.
 *
 * @author zhanglei.
 * @date 2025/2/25 11:11.
 * @description TODO.
 */
@Data
public class ToolCallAccumulator {

    private String id;

    private String name;

    private StringBuilder arguments = new StringBuilder();

    private ObjectMapper objectMapper = new ObjectMapper();

    public void appendArguments(String chunk) {
        arguments.append(chunk);
    }

    public boolean isComplete() {
        if (name == null || arguments.isEmpty()) return false;
        try {
            objectMapper.readTree(arguments.toString());
            return true;
        } catch (JsonProcessingException e) {
            return false;
        }
    }

    public String getArgumentsJson() {
        return arguments.toString();
    }

}
